package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduExamRecordMapper;
import com.zenith.edu.po.domain.EduExamRecord;
import com.zenith.edu.po.dto.EduExamRecordDTO;
import com.zenith.edu.po.vo.EduExamRecordVO;
import com.zenith.edu.service.EduExamRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduExamRecordServiceImpl extends ServiceImpl<EduExamRecordMapper, EduExamRecord> implements EduExamRecordService {
    
    @Override
    public EduExamRecordVO createExamRecord(EduExamRecordDTO dto) {
        EduExamRecord examRecord = new EduExamRecord();
        BeanUtils.copyProperties(dto, examRecord);
        this.save(examRecord);
        
        EduExamRecordVO vo = new EduExamRecordVO();
        BeanUtils.copyProperties(examRecord, vo);
        return vo;
    }
    
    @Override
    public EduExamRecordVO getExamRecordById(Long id) {
        EduExamRecord examRecord = this.getById(id);
        if (examRecord == null) {
            return null;
        }
        
        EduExamRecordVO vo = new EduExamRecordVO();
        BeanUtils.copyProperties(examRecord, vo);
        return vo;
    }
    
    @Override
    public EduExamRecordVO updateExamRecord(EduExamRecordDTO dto) {
        EduExamRecord examRecord = new EduExamRecord();
        BeanUtils.copyProperties(dto, examRecord);
        this.updateById(examRecord);
        
        EduExamRecordVO vo = new EduExamRecordVO();
        BeanUtils.copyProperties(examRecord, vo);
        return vo;
    }
    
    @Override
    public boolean deleteExamRecord(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduExamRecordVO> getExamRecordList() {
        List<EduExamRecord> examRecordList = this.list();
        return examRecordList.stream().map(examRecord -> {
            EduExamRecordVO vo = new EduExamRecordVO();
            BeanUtils.copyProperties(examRecord, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}